package com.agent.vpsserver.modules.server.controller;


import com.agent.vpsserver.common.dto.AdminAccountTokenDTO;
import com.agent.vpsserver.common.dto.AdminPageTokenRequestDTO;
import com.agent.vpsserver.common.dto.PageBean;
import com.agent.vpsserver.common.dto.Result;
import com.agent.vpsserver.common.utils.mapping.BeansUtils;
import com.agent.vpsserver.modules.server.entity.pojo.ServerInfoDO;
import com.agent.vpsserver.modules.server.request.ServerInfoSaveRequest;
import com.agent.vpsserver.modules.server.response.ServerInfoPageResponse;
import com.agent.vpsserver.modules.server.service.ServerInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 服务器信息(ServerInfo)表控制层
 *
 * @author guochao
 * @since 2024-03-12 23:50:20
 */
@RestController
@RequestMapping("admin/serverInfo")
public class ServerInfoController {
    /**
     * 服务对象
     */
    @Resource
    private ServerInfoService serverInfoService;

    @PostMapping(value = "/page")
    @ApiOperation(value = "分页")
    public Result<PageBean<ServerInfoPageResponse>> page(@RequestBody @Valid AdminPageTokenRequestDTO request) {
        return Result.success(serverInfoService.pageData(request));
    }

    @PostMapping(value = "/list")
    @ApiOperation(value = "列表")
    public Result<List<ServerInfoPageResponse>> list(@RequestBody @Valid AdminAccountTokenDTO request) {
        return Result.success(serverInfoService.listData(request));
    }

    @PostMapping(value = "/save")
    @ApiOperation(value = "保存")
    public Result<Boolean> save(@RequestBody @Valid ServerInfoSaveRequest request) {
        ServerInfoDO serverInfo = BeansUtils.map(request, ServerInfoDO.class);
        serverInfoService.saveOrUpdate(serverInfo);
        return Result.success(Boolean.TRUE);
    }
}
